﻿using System;
using System.Windows.Controls;
using System.Windows.Input.Manipulations;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace Wintellect.Touch
{
    public partial class MultiManipulatePage : Page
    {
        public MultiManipulatePage()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }


        private void TouchShapeBehavior_ManipulationStarted(Object sender, Manipulation2DStartedEventArgs e)
        {
            var senderShape = (Shape)sender;
            senderShape.Tag = senderShape.Fill;
            senderShape.Fill = new SolidColorBrush(Colors.Yellow);
        }

        private void TouchShapeBehavior_ManipulationDelta(Object sender, Manipulation2DDeltaEventArgs e)
        {
            var senderShape = (Shape)sender;
            var translateTransform = (TranslateTransform)senderShape.RenderTransform;
            translateTransform.X += e.Delta.TranslationX;
            translateTransform.Y += e.Delta.TranslationY;
        }

        private void TouchShapeBehavior_ManipulationCompleted(Object sender, Manipulation2DCompletedEventArgs e)
        {
            var senderShape = (Shape)sender;
            //TODO: This should really be done at the end of inertia, otherwise it will take the original color and keep moving...
            senderShape.Fill = senderShape.Tag as Brush;
        }
    }
}
